
%% Support macros for program code pretty formatting.
%% This file is in the public domain; do what you want with it.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{code}[2000/01/28 v1.1 code formatting support]

\usepackage{ifthen}
\usepackage{calc}

\makeatletter
\newlength{\@length}
\newcounter{codeindent}
\setcounter{codeindent}{0}

\newcommand{\codeindent}{\hspace*{\thecodeindent mm}}
\newcommand{\nextlevel}{\addtocounter{codeindent}{5}}
\newcommand{\prevlevel}{\addtocounter{codeindent}{-5}}

\newcommand{\block}[1]{%
 \settowidth{\@length}{{\def\br{ }{#1}}}%
 \ifthenelse{\@length > \textwidth}%
 {%
  \nextlevel{\def\br{\\ \codeindent}{#1}\prevlevel}%
 }%
 {%
  {\def\br{ }{#1}}%
 }%
}

\newcommand{\brblock}[3]{%  
 \settowidth{\@length}{{\def\br{ }{#1}{#3}{#2}}}% 
 \ifthenelse{\@length > \textwidth}%
 {%
   {#1}\nextlevel%
   {%
    \def\br{\\ \codeindent}\br%
    {#3}%
    \prevlevel\br{#2}}%
 }%
 {%
  {\def\br{ }{#1}{#3}{#2}}%
 }%
}

\endinput